package com.ruoyi.demowechatpay.utils;

import com.google.gson.JsonObject;
import org.apache.commons.lang3.RandomStringUtils;

public class WxPayMockUtils {

    /**
     * 生成模拟的支付回调JSON
     *
     * @param transactionId 微信支付订单号（如"420000123456789"）
     * @param outTradeNo    商户订单号
     */
    public static String createPaymentNotifyJson(String transactionId, String outTradeNo) {
        // 模拟加密数据（实际项目需按微信规范加密）
        String mockCiphertext = "mock_ciphertext_" + transactionId + "_" + outTradeNo;
        JsonObject resource = new JsonObject();
        resource.addProperty("algorithm", "AEAD_AES_256_GCM");
        resource.addProperty("ciphertext", mockCiphertext);
        resource.addProperty("associated_data", "transaction");
        resource.addProperty("nonce", RandomStringUtils.randomAlphanumeric(16));
        JsonObject root = new JsonObject();
        root.addProperty("id", "EV-2023123" + RandomStringUtils.randomNumeric(10));
        root.add("resource", resource);

        return root.toString();
    }

    /**
     * 生成模拟的退款回调JSON
     */
    public static String createRefundNotifyJson(String refundId) {

        // 模拟加密数据（实际项目需按微信规范加密）
        JsonObject resource = new JsonObject();
        resource.addProperty("algorithm", "AEAD_AES_256_GCM");
        resource.addProperty("ciphertext", "mock_refund_ciphertext_" + refundId);
        resource.addProperty("associated_data", "transaction");
        resource.addProperty("nonce", RandomStringUtils.randomAlphanumeric(16));

        JsonObject root = new JsonObject();
        root.addProperty("id", "EV-2023123"+ refundId);
        root.add("resource", resource);
        return root.toString();
    }

    /**
     * 生成测试用签名头（简化版）
     */
    public static String mockSignatureHeader() {
        return "mock_signature_" + System.currentTimeMillis();
    }
}